package com.cgtong.android.mvp.presenter;

import android.text.TextUtils;

import com.blankj.utilcode.util.ToastUtils;
import com.cgtong.android.bean.ActivityBean;
import com.cgtong.android.mvp.contract.MyParticipationContract;
import com.cgtong.android.mvp.model.MyParticipationModel;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;

import java.util.List;

/**
 * Created by Sky.Bing on 2017/10/25.
 */

public class MyParticipationPresenter implements MyParticipationContract.Presenter {
    private MyParticipationContract.View mView;
    private MyParticipationContract.Model mModel;

    public MyParticipationPresenter(MyParticipationContract.View view) {
        this.mView = view;
        mModel = new MyParticipationModel();
    }

    @Override
    public void getMyParticipation(int maxId, int pageSize) {
        mView.setEnableLoadMore(false);
        mModel.getMyParticipation(maxId, pageSize, new SimpleCallBack<List<List<ActivityBean>>>() {
            @Override
            public void onError(ApiException e) {
                mView.getMyParticipationActivityError(e);
            }

            @Override
            public void onSuccess(List<List<ActivityBean>> activityBeanList) {
                mView.showParticipationActivityList(true, ActivityBean.parseJsonOfDoubleList(activityBeanList));
                mView.setEnableLoadMore(true);
                mView.setRefreshing(false);
            }
        });
    }

    @Override
    public void loadMore(int maxId, int pageSize) {
        mModel.getMyParticipation(maxId, pageSize, new SimpleCallBack<List<ActivityBean>>() {
            @Override
            public void onError(ApiException e) {
                if (!TextUtils.isEmpty(e.getMessage())) ToastUtils.showLong(e.getMessage());
            }

            @Override
            public void onSuccess(List<ActivityBean> activityBeanList) {
                mView.showParticipationActivityList(false, activityBeanList);
                mView.setRefreshing(false);
            }
        });
    }
}